#include "alarmrecordeditdialog.h"

AlarmRecordEditDialog::AlarmRecordEditDialog(const QModelIndex &index, QWidget *parent)
    : QDialog(parent)
{
    setWindowTitle("编辑告警记录");
    setMinimumWidth(400);

    QVBoxLayout *mainLayout = new QVBoxLayout(this);

    // 状态选择
    QHBoxLayout *statusLayout = new QHBoxLayout();
    statusLayout->addWidget(new QLabel("处理状态:", this));
    m_statusCombo = new QComboBox(this);
    m_statusCombo->addItem("未处理", "未");
    m_statusCombo->addItem("已处理", "已");
    statusLayout->addWidget(m_statusCombo);
    mainLayout->addLayout(statusLayout);

    // 备注编辑
    QHBoxLayout *noteLayout = new QHBoxLayout();
    noteLayout->addWidget(new QLabel("处理备注:", this));
    m_noteEdit = new QTextEdit(this);
    noteLayout->addWidget(m_noteEdit);
    mainLayout->addLayout(noteLayout);

    // 按钮
    QHBoxLayout *buttonLayout = new QHBoxLayout();
    QPushButton *saveButton = new QPushButton("保存", this);
    QPushButton *cancelButton = new QPushButton("取消", this);
    buttonLayout->addWidget(saveButton);
    buttonLayout->addWidget(cancelButton);
    mainLayout->addLayout(buttonLayout);

    // 预填充当前值
    if (index.isValid()) {
        QString currentStatus = index.siblingAtColumn(4).data().toString();
        QString currentNote = index.siblingAtColumn(5).data().toString();
        m_statusCombo->setCurrentText(currentStatus == "未" ? "未处理" : "已处理");
        m_noteEdit->setText(currentNote);
    }

    connect(saveButton, &QPushButton::clicked, this, &QDialog::accept);
    connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
}

QString AlarmRecordEditDialog::getStatus() const
{
    return m_statusCombo->currentText();
}

QString AlarmRecordEditDialog::getNote() const
{
    return m_noteEdit->toPlainText();
}
